﻿using INTEX.DataBase.Tools;
using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Linq;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{
    public partial class ITXEXRPT
    { 
         
        private void TSTVVSMP(DataSet db)  
        {
            try
            {
                DataTable tbVVLIEF = dsSource.Tables["VVLIEF"];
                DataRow dwVV = tbVVLIEF.Rows[0];
                string src = "",str="";
                src = dwVV["VVNAME"].ToString().Trim();
                if (src == "")
                {
                    src = dwVV["DELNAME"].ToString().Trim();
                    if (src == "")
                    {
                        src = dwVV["CUSTOMER"].ToString().Trim();
                    }
                }
                exAgent.SetCellValue(7, 5, Helper.GetGB2312Value(src).Trim());
                src = dwVV["VVADR"].ToString().Trim();
                if (src == "")
                {
                    src = dwVV["DELADR"].ToString().Trim();
                    if (src == "")
                    {
                        src = dwVV["CUSTADR"].ToString().Trim();
                    }
                }
                exAgent.SetCellValue(8, 5, Helper.GetGB2312Value(src).Trim());
                src = dwVV["VVSTAFF"].ToString().Trim();
                if (src == "")
                {
                    src = dwVV["DELSTAFF"].ToString().Trim();
                    if (src == "")
                    {
                        src = dwVV["CUSTAFF"].ToString().Trim();
                    }
                }
                exAgent.SetCellValue(9, 5, Helper.GetGB2312Value(src).Trim());
                src = dwVV["VVTEL"].ToString().Trim();
                if (src == "")
                {
                    src = dwVV["DELTEL"].ToString().Trim();
                    if (src == "")
                    {
                        src = dwVV["CUTEL"].ToString().Trim();
                    }
                }
                src = src.Replace(":", "/");
                if (src.Trim().Length > 1)
                {
                    if (src.Substring(src.Length - 1, 1) == "/")
                    {
                        src = src.Substring(0, src.Length - 1);
                    }
                }
                exAgent.SetCellValue(10, 5, Helper.GetGB2312Value(src).Trim());
                src = dwVV["EXNO"].ToString().Trim();
                exAgent.SetCellValue(11, 5, Helper.GetGB2312Value(src).Trim());
                src = dwVV["NAM"].ToString().Trim();
                exAgent.SetCellValue(7, 29, Helper.GetGB2312Value(src).Trim());
                src = dwVV["TEL"].ToString().Trim();
                exAgent.SetCellValue(8, 29, Helper.GetGB2312Value(src).Trim());
                src = dwVV["MOB"].ToString().Trim();
                exAgent.SetCellValue(9, 29, Helper.GetGB2312Value(src).Trim());
                src = dwVV["MAIL"].ToString().Trim();
                exAgent.SetCellValue(10, 29, Helper.GetGB2312Value(src).Trim());


                src = dwVV["VVLIEFSCH"].ToString();
                exAgent.SetCellValue(14, 5, System.Convert.ToInt64(src));
                src = dwVV["ORDERNO"].ToString();
                exAgent.SetCellValue(14, 17, src);
                src = dwVV["CUPO"].ToString().Trim();
                exAgent.SetCellValue(14, 27, Helper.GetGB2312Value(src).Trim());
                src = dwVV["VKKNEUDAT"].ToString().Trim();
                exAgent.SetCellValue(14, 39, Helper.GetGB2312Value(src).Trim());
                src = dwVV["VVVERSDAT"].ToString().Trim(); 
                exAgent.SetCellValue(13, 39, Helper.GetGB2312Value(src).Trim());
                src = dwVV["PAYMENT"].ToString().Trim();
                exAgent.SetCellValue(319, 6, Helper.GetGB2312Value(src).Trim());
                src = dwVV["CURRENCY"].ToString().Trim();
                exAgent.SetCellValue(15, 35, "总金额 (" + Helper.GetGB2312Value(src).Trim() + ")");
                exAgent.SetCellValue(15, 26, "单价 (" + Helper.GetGB2312Value(src).Trim() + ")");

                int x = 17;
                DataTable tbVVT = dsSource.Tables["VVTLIEF"];
                string wid = "", totwid = "", gm = "", sqm = "", comp = "";
                foreach (DataRow dwVVT in tbVVT.Rows)
                {
                    src = dwVVT["VKPAUFPOS"].ToString();
                    exAgent.SetCellValue(x, 1, System.Convert.ToInt64(src));
                    src = Helper.GetGB2312Value(dwVVT["VKPART"].ToString().Trim());
                    src += Helper.GetGB2312Value(dwVVT["VAABEZ"].ToString().Trim());
                    exAgent.SetCellValue(x, 3, src);
                    src = Helper.GetGB2312Value(dwVVT["VKPFARBE"].ToString().Trim());
                    exAgent.SetCellValue(x, 13, src);
                    src = dwVVT["VVQTY"].ToString().Trim();
                    exAgent.SetCellValue(x, 19, System.Convert.ToDecimal(src));
                    src = dwVVT["VKPMEEH"].ToString().Trim();
                    exAgent.SetCellValue(x, 24, src);
                    src = dwVVT["PRICE"].ToString().Trim();
                    exAgent.SetCellValue(x, 26, System.Convert.ToDecimal(src));
                    src = dwVVT["WEIGHT"].ToString().Trim();
                    exAgent.SetCellValue(x, 29, src);
                    src = dwVVT["PRICE"].ToString().Trim();
                    exAgent.SetCellValue(x, 26, System.Convert.ToDecimal(src));
                    src = dwVVT["SUPP"].ToString().Trim();
                    exAgent.SetCellValue(x, 30, Helper.GetGB2312Value(src));
                    src = dwVVT["VALUE"].ToString().Trim();
                    exAgent.SetCellValue(x, 35, System.Convert.ToDecimal(src));

                    wid = dwVVT["WID"].ToString().Trim();
                    totwid = dwVVT["TOTWID"].ToString().Trim();
                    gm = dwVVT["GM"].ToString().Trim();
                    sqm = dwVVT["SQM"].ToString().Trim();
                    comp = Helper.GetGB2312Value(dwVVT["COMP"].ToString().Trim());
                    src = "成份:" + comp;
                    if (totwid != "0")
                    {
                        src = src + "   幅宽:" + totwid + "cm  ";
                    }
                    if (wid != "0")
                    {
                        src = src + wid + "cm（可裁）   ";
                    }
                    if (gm != "0")
                    {
                        src = src + "克重:" + gm + "g/m  " + sqm + "g/sqm ";
                    }
                    exAgent.SetCellValue(x + 1, 3, src);

                    src = Helper.GetGB2312Value(dwVVT["SUR"].ToString()).Trim();
                    if(src!="")
                    {
                        src = "附加费:" + src+"    ";
                    }
                    str = Helper.GetGB2312Value(dwVVT["DIS"].ToString()).Trim();
                    if (str != "")
                    {
                        src = src + "折扣:" + str;
                    }
                    str = Helper.GetGB2312Value(dwVVT["REMARK"].ToString()).Trim();
                    if (str != "")
                    {
                        src = src + "     " + str;
                    }

                    exAgent.SetCellValue(x + 2, 3, src);

                    x = x + 3;

                }

                DataTable tbLIEFKO = dsSource.Tables["LIEFKO"];
                DataRow dwLIEFKO = tbLIEFKO.Rows[0];
                if (dwVV["ACCOUNT"].ToString().Trim() == "STD")
                {
                    exAgent.SetCellValue(320, 2, "以上价格为含税到仓价格，相关样布费用请付款至：");
                }
                else
                {
                    exAgent.SetCellValue(320, 2, "以上价格为不含税到仓价格，相关样布费用请付款至：");
                }
                src = dwLIEFKO["ACCNAME"].ToString().Trim();
                exAgent.SetCellValue(321, 6, Helper.GetGB2312Value(src));
                src = dwLIEFKO["BANK"].ToString().Trim();
                exAgent.SetCellValue(322, 6, Helper.GetGB2312Value(src).Trim());
                src = dwLIEFKO["ACCOUNT"].ToString().Trim();
                exAgent.SetCellValue(323, 6, Helper.GetGB2312Value(src).Trim());

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);

            }            
        }
               
    }
}
